package leetcode.code1806;

import leetcode.IDebug;

public class Solution implements IDebug {

	public int reinitializePermutation(int n) {
		int ans = 1;
		int[] perm = new int[n];
		for (int i = 0; i < n; i++) {
			perm[i] = i;
		}
		while (true) {
			int[] arr = new int[n];
			for (int i = 0; i < n; i++) {
				if (i % 2 == 0) {
					arr[i] = perm[i / 2];
				} else {
					arr[i] = perm[n / 2 + (i - 1) / 2];
				}
			}
			boolean ok = true;
			for (int i = 0; i < n; i++) {
				if (arr[i] != i) {
					ok = false;
					break;
				}
			}
			if (ok) {
				return ans;
			}
			perm = arr;
			ans++;
		}
	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
